473,435 Members | 1,704 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,435 software developers and data experts.

Floating div

How do a create a floating div that will always stay in the same place
relative to the browser window as the user scrolls the main page? I guess an
adaptation of one of these floating menus that always stay in view would
work but I just need the few lines of code to keep it positioned a certain x
and y pix location from the window top left corner... Thanks!
Jul 23 '05 #1
6 26049
Simon Wigzell wrote:
How do a create a floating div that will always stay in the same place
relative to the browser window as the user scrolls the main page?


CSS2's position:fixed and a proper workaround for non-compliant
browsers. This has nothing to do with J(ava)Script, ask in
comp.infosystems.www.authoring.stylesheets.
PointedEars
Jul 23 '05 #2
Simon,
This is called a 'watermark' script; there are several examples on the web.
Here's a few URL's with the explanation and info on this javascript/dhtml tool:

http://www.javascript-page.com/watermark.html

http://www.dynamicdrive.com/dynamicindex4/logo.htm

http://www.ricocheting.com/js/watermark.html

Hope this helps!

Jim
Jul 23 '05 #3
JimMenees wrote:
This is called a 'watermark' script; there are several examples on the web.
Here's a few URL's with the explanation and info on this javascript/dhtml tool:
[...]


"Watermark scripts" have been utter nonsense since they have been conceived,
and eventually are utter nonsense since they are outdated. CSS2 provides
this feature much more reliable and performant.
PointedEars
Jul 23 '05 #4
"Simon Wigzell" <si**********@shaw.ca> writes:
How do a create a floating div that will always stay in the same place
relative to the browser window as the user scrolls the main page? I guess an
adaptation of one of these floating menus that always stay in view would
work but I just need the few lines of code to keep it positioned a certain x
and y pix location from the window top left corner... Thanks!


Use CSS 2 position:fixed for browsers that support it (all modern
browsers), and use a fallback for older browsers (including all IE
versions). The fallback is based on detecting scrolling and
repositioning the element. I would usually only bother putting in a
fallback for IE 5+, using IE conditional comments:

---
<style type="text/css">
#myfixed {
position: fixed;
top: 100px;
left: 50px;
}
</style>
<!--[if IE]>
<style type="text/css">
#myfixed { position:absolute; }
</style>
<script type="text/javascript">
window.onscroll = function() {
var root = (document.compatMode == "CSS1Compat"?
document.documentElement: document.body);
var elem = document.all["myfixed"];
elem.style.left = root.scrollLeft + 50 + "px";
elem.style.top = root.scrollTop + 100 + "px";
};
</script>
<![endif]-->
....
<div id="myfixed" style="width:100px;height:100px;border:1px solid black;">
HERE<br>I<br>AM
</div>
---

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #5
Lasse Reichstein Nielsen wrote:
"Simon Wigzell" <si**********@shaw.ca> writes:
How do a create a floating div that will always stay in the same place
relative to the browser window as the user scrolls the main page? I guess an
adaptation of one of these floating menus that always stay in view would
work but I just need the few lines of code to keep it positioned a certain x
and y pix location from the window top left corner... Thanks!


Use CSS 2 position:fixed for browsers that support it (all modern
browsers), and use a fallback for older browsers (including all IE
versions). The fallback is based on detecting scrolling and
repositioning the element. I would usually only bother putting in a
fallback for IE 5+, using IE conditional comments:


There are workarounds for IE 5+ that work without JScript.
Conditional comments are an important part of it, though.

<http://www.fabrice-pascal.de/artikel/posfixedie6/>

<http://translate.google.com/translate?u=http://www.fabrice-pascal.de/artikel/posfixedie6/&langpair=de%7Cen&hl=en&ie=Unknown&oe=ISO-8859-1>
(Beware of the [awful] translation, it translates the stylesheets as well!)
X-Post & F'up2 comp.infosystems.www.authoring.stylesheets

PointedEars
Jul 23 '05 #6
Thanks to all who replied, my problem is resolved.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: JS | last post by:
We have the same floating point intensive C++ program that runs on Windows on Intel chip and on Sun Solaris on SPARC chips. The program reads the exactly the same input files on the two platforms....
5
by: Anton Noll | last post by:
We are using Visual Studio 2003.NET (C++) for the development of our software in the fields digital signal processing and numerical acoustics. One of our programs was working correctly if we are...
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
7
by: Vinoth | last post by:
I'm working in an ARM (ARM9) system which does not have Floating point co-processor or Floating point libraries. But it does support long long int (64 bits). Can you provide some link that would...
15
by: michael.mcgarry | last post by:
Hi, I have a question about floating point precision in C. What is the minimum distinguishable difference between 2 floating point numbers? Does this differ for various computers? Is this...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
4
by: jacob navia | last post by:
Hi people I continue to work in the tutorial for lcc-win32, and started to try to explain the floating point flags. Here is the relevant part of the tutorial. Since it is a difficult part, I...
32
by: ma740988 | last post by:
template <class T> inline bool isEqual( const T& a, const T& b, const T epsilon = std::numeric_limits<T>::epsilon() ) { const T diff = a - b; return ( diff <= epsilon ) && ( diff >= -epsilon );...
39
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody...
6
by: Jeremy | last post by:
I've got a floating div which becomes visible when a link is clicked. I want the div to be hidden when the user clicks anywhere on the page except for whithin the div. What is the best way to do...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.